#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ(2.61)
AC_INIT(libtrckr1, 1.0.0, http://code.google.com/p/libtrckr)
AC_CONFIG_SRCDIR([Filter.h])
AC_CONFIG_HEADER([config.h])
#AC_DISABLE_STATIC
AM_INIT_AUTOMAKE
AC_LANG([C++])
#some define
AC_SUBST(LIBTRCKRVERSION, `echo $VERSION | tr . : `)
AC_SUBST(CXXFLAGS,"-g")

# Checks for programs.
AC_PROG_CXX
AC_PROG_CC
AC_PROG_CPP
AC_PROG_INSTALL
AC_PROG_LN_S
AC_PROG_MAKE_SET
AC_PROG_LIBTOOL 
AC_CHECK_PROG([PKCONF],[pkg-config],[ok])

# Checks for libraries.
# is pkg macro is defined
# and what to do is the answer is NO :)


#PKG_CHECK_MODULES([soundtouch], [soundtouch >= 1.0])

AC_ARG_WITH([alsa],
	[AS_HELP_STRING([--without-alsa],
		[disable support for alsa])],
	[],
	[with_alsa=yes])
AC_ARG_WITH([jack],
	[AS_HELP_STRING([--without-jack],
		[disable support for Jack])],
	[],
	[with_jack=yes])
AC_ARG_WITH([arts],
	[AS_HELP_STRING([--without-arts],
		[disable support for aRts])],
	[],
	[with_arts=yes])
AC_ARG_WITH([vector],
	[AS_HELP_STRING([--with-vector], [enable support for stl vector])],
	[],
	[with_vector=no])
AS_IF([test "x$with_vector" != xno], 
      [AC_DEFINE([USE_VECTOR],[1],[Define is you think that stl vector is not bugged, id est you don't have invalid next size or else error using vector]) 
      ])

#LIBALSA=
AS_IF([test "x$with_alsa" != xno],
		[AC_CHECK_LIB([pthread], [pthread_create])	
            AC_CHECK_LIB([asound], [snd_pcm_open],
              [AC_SUBST([LIBALSA], ["-lasound"])
               AC_DEFINE([HAVE_LIBALSA], [1],
                         [Define if you have libasound])
              ],
              [AC_MSG_FAILURE(
                 [asound test failed (--without-alsa to disable)])],
              [])])
AS_IF([test "$PKCONF" == "ok"],[
	PKG_CHECK_MODULES([sndfile], [sndfile >= 1.0], AC_DEFINE(HAVE_LIBSNDFILE,1))
	PKG_CHECK_MODULES([fftw3], [fftw3 >= 3.0], AC_DEFINE(HAVE_LIBFFTW3,1))
	AS_IF([test "x$with_jack" != xno ],[
		PKG_CHECK_MODULES([JACK], [jack], [AC_DEFINE([HAVE_LIBJACK],[1])
		])]
	)
	PKG_CHECK_MODULES([samplerate],[samplerate >= 0.1], [AC_DEFINE([HAVE_SAMPLERATE],[1],[Define to 1 if sampleterate is installed] )])
],[
	AC_CHECK_LIB([fftw3], [fftw_execute])
	AC_CHECK_LIB([sndfile], [sf_open])
AS_IF([test "x$with_jack" != xno ],
	[AC_CHECK_LIB([jack], [jack_client_open],
	 [AC_SUBST([LIBJACK], ["-ljack"])
          AC_DEFINE([HAVE_LIBJACK],[1], [Define if you  havelibjack])
         ],
         [AC_MSG_FAILURE( 
		[jack test failed (--without-jack to disable)])],
         [])])

])
AS_IF([ test "x$with_arts" != xno],
	[AC_CHECK_LIB([pthread], [pthread_create])
	 AC_CHECK_LIB([artsc], [arts_init],
		[ AC_SUBST(ARTSCFLAG, `artsc-config --cflags`)
		  AC_SUBST(ARTSCLIBS, `artsc-config --libs`)
		  AC_DEFINE([HAVE_LIBARTS],[1],[Define if you have libarsc] )
		],
         [AC_MSG_FAILURE( 
		[arts test failed (--without-arts to disable)])],
         [])])
# Checks for header files.
AC_HEADER_STDC
AC_HEADER_DIRENT
AC_CHECK_HEADERS([stdlib.h])

# Checks for typedefs, structures, and compiler characteristics.

AC_HEADER_STDBOOL
AC_C_CONST
AC_TYPE_SIZE_T
AC_TYPE_UINT64_T
AC_TYPE_INT32_T
AC_CHECK_TYPE(loff_t,,[AC_DEFINE([loff_t],[uint64_t], [Define loff_t])])
AC_TYPE_INT16_T
AC_TYPE_UINT8_T
AC_TYPE_INT8_T

# config.h protection
AH_TOP([#ifndef CONFIG_H
	#define CONFIG_H 1])
AH_BOTTOM([#endif /*CONFIG_H*/])

# Checks for library functions.
AC_FUNC_MALLOC
AC_FUNC_REALLOC
AC_FUNC_CLOSEDIR_VOID
AC_CHECK_FUNCS([pow sqrt floor memset strerror])

# output files
AC_CONFIG_FILES([
  Makefile
  libtrckr-$VERSION.pc:libtrckr.pc.in
])
AC_CONFIG_LINKS([libtrckr.pc:libtrckr-$VERSION.pc])
AC_OUTPUT
